package com.qf.controller;

import com.alibaba.fastjson.JSON;
import com.qf.pojo.Type;
import com.qf.service.GoodsTypeService;
import com.qf.service.impl.GoodsTypeServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品类型管理
 * @author 千锋健哥
 */
@WebServlet("/type")
public class GoodsTypeController extends BaseController{

    /**
     * 查询商品分类列表下拉菜单数据
     * @param request
     * @param response
     * @return
     */
    public String findAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //1. 调用service完成查询
        GoodsTypeService goodsTypeService = new GoodsTypeServiceImpl();
        List<Type> list = goodsTypeService.findGoodsTypeAll();

        //2. 将数据转换成json格式字符串
        String jsonStr = JSON.toJSONString(list);

        //3. 设置响应头为json格式数据, 字符集为utf-8
        response.setContentType("application/json;charset=utf-8");

        //4. 通过响应返回json数据
        response.getWriter().write(jsonStr);
        return null;
    }
}
